﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Smart.Model
{
    [System.Serializable]
    public class EndPointInfo
    {
        public ServerType eServerType;
        public string ipandport;
    }
    public class GameEntry : MonoBehaviour
    {
        [SerializeField]
        protected EndPointInfo[] mEndPoints = new EndPointInfo[0];

        NetOutComponent mNet;
        public static GameEntry Instance { get; private set; }

        public void Send(ushort msgId,Google.Protobuf.IMessage message)
        {
            if(null != mNet)
            {
                mNet.Send(ServerType.ST_LOGIC, msgId, message);
            }
        }

        private void Awake()
        {
            Instance = this;
            DontDestroyOnLoad(this.gameObject);
            this.gameObject.AddComponent<CppLog>();
            this.gameObject.AddComponent<NetMessageQueue>();
            mNet = this.gameObject.AddComponent<NetOutComponent>();

            for(int i = 0; i < mEndPoints.Length;++i)
            {
                var endpoint = mEndPoints[i];
                mNet.Connect(endpoint.eServerType,endpoint.ipandport);
            }
        }
    }
}